<template>
    <table border="1" >
        <tr>
            <td colspan="2" style="text-algin:center;">添加</td>
        </tr>
        <tr>
            <td>名称</td>
            <td><input type="text" placeholder="请输入名称" v-model="info.name"/></td>
        </tr>
        <tr>
            <td>密码</td>
            <td><input type="password" placeholder="请输入密码" v-model="info.pwd"/></td>
        </tr>
        <tr>
            <td>邮箱</td>
            <td><input type="text" placeholder="请输入邮箱" v-model="info.email"/></td>
        </tr>
        <tr>
            <td>联系方式</td>
            <td><input type="text" placeholder="请输入联系方式" v-model="info.phone"/></td>
        </tr>
        <tr>
            <td>身份证号码</td>
            <td><input type="text" placeholder="请输入身份证号码" v-model="info.idCard"/></td>
        </tr>
        <tr>
            <td><input type="button" value="添加" @click="Add" /></td>
        </tr>
    </table>
</template>
<script setup lang="ts">

    import {ref} from 'vue';
    import axios from 'axios';

    const info=ref({
         name:"",
         pwd:"",
         email:"",
         phone:"",
         idCard:""
    })

    const Add=()=>{
        if(info.value.name==""){
            alert('名称不能为空');
            return;
        }
        if(info.value.pwd==""){
            alert('密码不能为空');
            return;
        }
        var yanzheng=/^\w+((-\w+)|(\.\w+))*@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
        if(!yanzheng.test(info.value.email)){
            alert('邮箱格式不正确');
            return;
        }
        var sfz=/^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
        if(!sfz.test(info.value.idCard)){
            alert('身份证格式不正确');
            return;
        }
        axios.post("https://localhost:7112/api/member/AddMember",info.value)
        .then(res=>{
            if(res.data>0){
                alert('添加成功');
            }
            else{
                alert('添加失败');
            }
        })
    }

</script>